|
|
| How
Inpout32.dll works |
If you don't know what is
Inpout32.dll, please read it here and then
continue.
How it works
The outstanding
feature of Inpout32.dll is , it can work with all the windows
versions without any modification in user code or the DLL itself.
This tutorial describes how it is achieved, what programming methods
used, what are the APIs used, etc.... The Dll will check the
operating system version when functions are called, and if the
operating system is WIN9X, the DLL will use _inp() and _outp
functions for reading/writing the parallel port. On the other hand,
if the operating system is WIN NT, 2000 or XP, it will install a
kernel mode driver and talk to parallel port through that driver.
The user code will not be aware of the OS version on which it is
running. This DLL can be used in WIN NT clone operating systems as
if it is WIN9X. The flow chart of the program is given below.
The two important
building blocks of this program are
1) A kernel mode device
driver embedded in the DLL in binary form
2) The DLL
itself
Kernel mode driver Hwinterface.sys
The source code of Hwinterface.sys kernel mode
driver is located in "kernel_mode_driver_source" directory. Where
"hwinterfacedrv.c" is the main application source file. Three
functions implemented in the driver are
1) 'DriverEntry' ,
Called when driver is loaded. Creates device object and symbolic
links.
2) 'hwinterfaceUnload', Called when driver is
unloaded, performs clean up
3) 'hwinterfaceDeviceControl',
handles calls made through DeviceIOControl API. Performs reading
writing to the parallel port according to the control code
passed.
The DLL Inpout32
The functions
in the DLL are implemented in two source files, "inpout32drv.cpp"
and "osversion.cpp". osversion.cpp checks the version of operating
system. "inpout32drv.cpp" does installing the kernel mode driver,
loading it , writing/ reading parallel port etc... The two functions
exported from inpout32.dll are
1) 'Inp32', reads data from a
specified parallel port register.
2) 'Out32', writes data to
specified parallel port register.
the other functions
implemented in Inpout32.dll are
1) 'DllMain', called when
dll is loaded or unloaded. When the dll is loaded , it checks the OS
version and loads hwinterface.sys if needed.
2)
'Closedriver', close the opened driver handle. called before
unloading the driver.
3) 'Opendriver', open a handle to
hwinterface driver.
4) 'inst' , Extract 'hwinterface.sys'
from binary resource to 'systemroot\drivers' directory and creates a
service. This function is called when 'Opendriver' function fails to
open a valid handle to 'hwinterface' service.
5) 'start' ,
starts the hwinterface service using Service Control Manager
APIs.
6) 'SystemVersion' Checks the OS version and returns
appropriate code.
What is hwinterface.ocx ActiveX
control
It is an activex control with same features
of Inpout32.dll. It can be used either with VC++ or VB. But it gives
great convenience when used with VB. Data can be written to parallel
port using Outport method and can be read using Inport
method.
Download Inpout32.dll and
source code here
Useful
links
Windows NT/Windows 2000/WDM
Driver FAQ by Jamie E. Hanrahan
Programming
Windows Driver Model by Walter Oney
Details of all the
APIs used is available at MSDN Online
|
| |
|